package leetcode;

import java.util.Stack;

/**
 * @author 榆关
 * 用两个栈实现队列的push和pop
 */
public class queue {
    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();
    //队列是先进先出FIFO，栈是后进先出LIFO
    //用一个栈入队列，一个栈出队列
    public void push(int a){
        stack1.push(a);
    }
    public int pop(){
        if(stack1.isEmpty()&&stack2.isEmpty()){
            throw new RuntimeException("Quere is empty");
        }
        if(stack2.isEmpty()){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }
}
